///////////////////////////////////////////////////////////////
// File: "CChallengeState.cpp"
// Author: Ryan Burkevich (RB)
// Purpose: To contain all challenge functionality.
///////////////////////////////////////////////////////////////

#include "CChallengeState.h"
#include "CBitmapFontEngine.h"
#include "CWiimote.h"
#include "CProfileManager.h"
#include "CLevelSelectState.h"
#include "CGame.h"
#include "CTransitionScreen.h"
#include "CGamePlayState.h"
#include "COptionsState.h"
#include "../Wrappers/CSGD_DirectInput.h"
#include "../Wrappers/CSGD_TextureManager.h"
#include "CSoundManager.h"

CChallengeState::CChallengeState()
{
	m_nUDChoice = 0;
	m_nFontID = -1;
	m_nCurrentLevel = 1;
}

CChallengeState::~CChallengeState()
{

}

void CChallengeState::Enter()
{
	m_nFontID = CBitmapFontEngine::GetInstance()->LoadFont("BS_TechDemoTitle.xml");
	m_cScreen.LoadScreen("Screens/BS_LevelSelectScreen.xml");
	m_nUDChoice = 0;
	m_nCurrentLevel = CProfileManager::GetInstance()->GetCurrentProfile()->GetWhichLevelPlaying();
	m_bExitingToGame = false;
}
		
void CChallengeState::Exit()
{

}
	
bool CChallengeState::Input(float fElapsedTime)
{
	CWiimote* pWii = CWiimote::GetInstance();
	CProfileManager* pPM = CProfileManager::GetInstance();
	CSGD_DirectInput* pDI = CSGD_DirectInput::GetInstance();

	if (pWii->IsButtonJustPressed(WII_HOME) || pDI->KeyPressed(DIK_ESCAPE))
	{
		CSoundManager::GetInstance()->PlaySoundIndxUnBuffered(SOUND_MENU_SELECT);
		CGame::GetInstance()->ChangeState(CLevelSelectState::GetInstance());
	}

	if(pDI->KeyPressed(DIK_UP) || pWii->IsButtonJustPressed(WII_UP))
	{
		CSoundManager::GetInstance()->PlaySoundIndxUnBuffered(SOUND_MENU_MOVE);
		m_nUDChoice--;
	}
	else if(pDI->KeyPressed(DIK_DOWN) || pWii->IsButtonJustPressed(WII_DOWN))
	{
		CSoundManager::GetInstance()->PlaySoundIndxUnBuffered(SOUND_MENU_MOVE);
		m_nUDChoice++;
	}

	if(m_nUDChoice > 1) 
		m_nUDChoice = 0;
	else if(m_nUDChoice < 0) 
		m_nUDChoice = 1;

	if (pWii->IsButtonJustPressed(WII_A) || pDI->KeyPressed(DIK_RETURN))
	{
		CSoundManager::GetInstance()->PlaySoundIndxUnBuffered(SOUND_MENU_SELECT);
		if(m_nUDChoice == 0)
		{
			if(pPM->GetCurrentProfile()->GetWhichLevelPlaying() == 1 || pPM->GetCurrentProfile()->GetWhichLevelPlaying() == 3 || pPM->GetCurrentProfile()->GetWhichLevelPlaying() == 4 || pPM->GetCurrentProfile()->GetWhichLevelPlaying() == 5 || pPM->GetCurrentProfile()->GetWhichLevelPlaying() == 6 || pPM->GetCurrentProfile()->GetWhichLevelPlaying() == 8)
			{
				COptionsState::GetInstance()->SetDifficulty(NORMAL);
			}
			else if(pPM->GetCurrentProfile()->GetWhichLevelPlaying() == 10)
			{
				COptionsState::GetInstance()->SetDifficulty(HARD);
			}
			else if(pPM->GetCurrentProfile()->GetWhichLevelPlaying() == 9 || pPM->GetCurrentProfile()->GetWhichLevelPlaying() == 2 || pPM->GetCurrentProfile()->GetWhichLevelPlaying() == 7)
			{
				COptionsState::GetInstance()->SetDifficulty(XTREME);
			}
			CGamePlayState::GetInstance()->SetLevel(pPM->GetCurrentProfile()->GetWhichLevelPlaying());
			CGamePlayState::GetInstance()->SetIsChallenge(true);
			m_bExitingToGame = true;
		}
		else if(m_nUDChoice == 1)
		{
			CGame::GetInstance()->ChangeState(CLevelSelectState::GetInstance());
		}
	}

	return true;
}

void CChallengeState::Update(float fElapsedTime)
{
	if(m_bExitingToGame)
		CTransitionScreen::GetInstance()->ChangeTo(CGamePlayState::GetInstance());

}

void CChallengeState::Render()
{
	m_cScreen.RenderScreen();

	CBitmapFontEngine* pBFE = CBitmapFontEngine::GetInstance();

	int TopX= m_cScreen.GetPosObjMembers("Top",XPOS);
	int TopY= m_cScreen.GetPosObjMembers("Top",YPOS);

	int LeftX = m_cScreen.GetPosObjMembers("Left",XPOS);
	int LeftY = m_cScreen.GetPosObjMembers("Left",YPOS);

	int RightX = m_cScreen.GetPosObjMembers("Right",XPOS);
	int RightY = m_cScreen.GetPosObjMembers("Right",YPOS);

	pBFE->RenderString("Challenge", m_nFontID, 0, 0xff00ff00, TopX+30, TopY+25, 0);
	
	pBFE->RenderString("Play?", m_nFontID, 0, 0xff00ff00, RightX+45, RightY, 0);
		
	if(m_nUDChoice == 0)
	{
		pBFE->RenderString("Yes", m_nFontID, 0, 0xffffff00, RightX+70, RightY+80, 0);
		pBFE->RenderString("No", m_nFontID, 0, 0xff00ff00, RightX+75, RightY+120, 0);
	}
	else if(m_nUDChoice == 1)
	{
		pBFE->RenderString("Yes", m_nFontID, 0, 0xff00ff00, RightX+70, RightY+80, 0);
		pBFE->RenderString("No", m_nFontID, 0, 0xffffff00, RightX+75, RightY+120, 0);
	}
	
	switch(m_nCurrentLevel)
	{
	case 1:
		pBFE->RenderString("Beat level", m_nFontID, 0, 0xff00ff00, LeftX+15, LeftY+115, 0, .8f, .8f);
		pBFE->RenderString("in under", m_nFontID, 0, 0xff00ff00, LeftX+30, LeftY+155, 0, .8f, .8f);
		pBFE->RenderString("10 secs", m_nFontID, 0, 0xff00ff00, LeftX+20, LeftY+195, 0, .8f, .8f);
		pBFE->RenderString("Difficulty", m_nFontID, 0, 0xffffff00, LeftX+5, LeftY+300, 0, .8f, .8f);
		pBFE->RenderString("n00b", m_nFontID, 0, 0xff00ff00, LeftX+85, LeftY+340, 0, .8f, .8f);
		break;
	case 2:
		pBFE->RenderString("Destroy", m_nFontID, 0, 0xff00ff00, LeftX+20, LeftY+105, 0, .8f, .8f);
		pBFE->RenderString("Targeting", m_nFontID, 0, 0xff00ff00, LeftX+20, LeftY+145, 0, .8f, .8f);
		pBFE->RenderString("Laser", m_nFontID, 0, 0xff00ff00, LeftX+40, LeftY+185, 0, .8f, .8f);
		pBFE->RenderString("No Deaths", m_nFontID, 0, 0xff00ff00, LeftX+20, LeftY+245, 0, .8f, .8f);
		pBFE->RenderString("Difficulty", m_nFontID, 0, 0xffffff00, LeftX+5, LeftY+300, 0, .8f, .8f);
		pBFE->RenderString("XTREME!", m_nFontID, 0, 0xff00ff00, LeftX+65, LeftY+340, 0, .8f, .8f);
		break;
	case 3:
		pBFE->RenderString("Beat Level", m_nFontID, 0, 0xff00ff00, LeftX+15, LeftY+105, 0, .8f, .8f);
		pBFE->RenderString("in under", m_nFontID, 0, 0xff00ff00, LeftX+30, LeftY+145, 0, .8f, .8f);
		pBFE->RenderString("3", m_nFontID, 0, 0xff00ff00, LeftX+125, LeftY+185, 0, .8f, .8f);
		pBFE->RenderString("rotations", m_nFontID, 0, 0xff00ff00, LeftX+20, LeftY+225, 0, .8f, .8f);
		pBFE->RenderString("Difficulty", m_nFontID, 0, 0xffffff00, LeftX+5, LeftY+300, 0, .8f, .8f);
		pBFE->RenderString("n00b", m_nFontID, 0, 0xff00ff00, LeftX+85, LeftY+340, 0, .8f, .8f);
		break;
	case 4:
		pBFE->RenderString("Beat Level", m_nFontID, 0, 0xff00ff00, LeftX+15, LeftY+105, 0, .8f, .8f);
		pBFE->RenderString("with a key", m_nFontID, 0, 0xff00ff00, LeftX+15, LeftY+145, 0, .8f, .8f);
		pBFE->RenderString("left in", m_nFontID, 0, 0xff00ff00, LeftX+35, LeftY+185, 0, .8f, .8f);
		pBFE->RenderString("inventory", m_nFontID, 0, 0xff00ff00, LeftX+20, LeftY+225, 0, .8f, .8f);
		pBFE->RenderString("Difficulty", m_nFontID, 0, 0xffffff00, LeftX+5, LeftY+300, 0, .8f, .8f);
		pBFE->RenderString("n00b", m_nFontID, 0, 0xff00ff00, LeftX+85, LeftY+340, 0, .8f, .8f);		
		break;
	case 5:
		pBFE->RenderString("Kill a", m_nFontID, 0, 0xff00ff00, LeftX+30, LeftY+115, 0, .8f, .8f);
		pBFE->RenderString("jumping", m_nFontID, 0, 0xff00ff00, LeftX+50, LeftY+155, 0, .8f, .8f);
		pBFE->RenderString("Enemy", m_nFontID, 0, 0xff00ff00, LeftX+30, LeftY+195, 0, .8f, .8f);
		pBFE->RenderString("Difficulty", m_nFontID, 0, 0xffffff00, LeftX+5, LeftY+300, 0, .8f, .8f);
		pBFE->RenderString("n00b", m_nFontID, 0, 0xff00ff00, LeftX+85, LeftY+340, 0, .8f, .8f);
		break;
	case 6:
		pBFE->RenderString("Use Both", m_nFontID, 0, 0xff00ff00, LeftX+30, LeftY+135, 0, .8f, .8f);
		pBFE->RenderString("Keys", m_nFontID, 0, 0xff00ff00, LeftX+50, LeftY+175, 0, .8f, .8f);
		pBFE->RenderString("Difficulty", m_nFontID, 0, 0xffffff00, LeftX+5, LeftY+300, 0, .8f, .8f);
		pBFE->RenderString("n00b", m_nFontID, 0, 0xff00ff00, LeftX+85, LeftY+340, 0, .8f, .8f);
		break;
	case 7:
		pBFE->RenderString("Finish", m_nFontID, 0, 0xff00ff00, LeftX+30, LeftY+85, 0, .8f, .8f);
		pBFE->RenderString("with 1", m_nFontID, 0, 0xff00ff00, LeftX+50, LeftY+125, 0, .8f, .8f);
		pBFE->RenderString("of each", m_nFontID, 0, 0xff00ff00, LeftX+30, LeftY+165, 0, .8f, .8f);
		pBFE->RenderString("bomb in", m_nFontID, 0, 0xff00ff00, LeftX+40, LeftY+205, 0, .8f, .8f);
		pBFE->RenderString("Inventory", m_nFontID, 0, 0xff00ff00, LeftX+10, LeftY+245, 0, .8f, .8f);
		pBFE->RenderString("Difficulty", m_nFontID, 0, 0xffffff00, LeftX+5, LeftY+300, 0, .8f, .8f);
		pBFE->RenderString("XTREME!", m_nFontID, 0, 0xff00ff00, LeftX+85, LeftY+340, 0, .8f, .8f);
		break;
	case 8:
		pBFE->RenderString("Kill 3", m_nFontID, 0, 0xff00ff00, LeftX+30, LeftY+135, 0, .8f, .8f);
		pBFE->RenderString("Enemies", m_nFontID, 0, 0xff00ff00, LeftX+50, LeftY+175, 0, .8f, .8f);
		pBFE->RenderString("Difficulty", m_nFontID, 0, 0xffffff00, LeftX+5, LeftY+300, 0, .8f, .8f);
		pBFE->RenderString("n00b", m_nFontID, 0, 0xff00ff00, LeftX+85, LeftY+340, 0, .8f, .8f);
		break;
	case 9:
		pBFE->RenderString("Kill a", m_nFontID, 0, 0xff00ff00, LeftX+30, LeftY+135, 0, .8f, .8f);
		pBFE->RenderString("Enemy", m_nFontID, 0, 0xff00ff00, LeftX+50, LeftY+175, 0, .8f, .8f);
		pBFE->RenderString("Difficulty", m_nFontID, 0, 0xffffff00, LeftX+5, LeftY+300, 0, .8f, .8f);
		pBFE->RenderString("XTREME!", m_nFontID, 0, 0xff00ff00, LeftX+85, LeftY+340, 0, .8f, .8f);
		break;
	case 10:
		pBFE->RenderString("Destory", m_nFontID, 0, 0xff00ff00, LeftX+30, LeftY+125, 0, .8f, .8f);
		pBFE->RenderString("at least", m_nFontID, 0, 0xff00ff00, LeftX+50, LeftY+165, 0, .8f, .8f);
		pBFE->RenderString("6 Blocks", m_nFontID, 0, 0xff00ff00, LeftX+30, LeftY+205, 0, .8f, .8f);
		pBFE->RenderString("Difficulty", m_nFontID, 0, 0xffffff00, LeftX+5, LeftY+300, 0, .8f, .8f);
		pBFE->RenderString("Hard", m_nFontID, 0, 0xff00ff00, LeftX+85, LeftY+340, 0, .8f, .8f);
		break;
	}
}